import{login}from "./user.js"
var nameInp=document.getElementById("user_name")
    var namespan=nameInp.nextElementSibling;
    var pwdInp=document.getElementById("user_pwd")
    var pwdspan=pwdInp.nextElementSibling
    var btn=document.getElementById("button")
    btn.onclick=function(){
       if(nameInp.value&&pwdInp.value){
        login(nameInp.value,pwdInp.value).then(function(result){
             if(result.status){
                 localStorage.setItem("user",result.user)
                 localStorage.setItem("user_id",result.id)
                 localStorage.setItem("pwd",result.pwd)
                 var backurl=localStorage.getItem("backurl")
                 if(backurl){
                     localStorage.removeItem("backurl")
                     location.href=backurl;
                 }
                 else{
                    location.href="index.html"
                 }
             }
             else{
               alert("用户名或密码错误")
             }
        })
       }
    }